/**
 * ...
 * @author Krzysztof Rozalski
 */

package hapi.physics;
import hapi.math.MathUtil;

class Speed {

	public var metersPerSecond(default, null):Float;
	public var kmPerHour(getKmPerHour, never):Float;
	public var milesPerHour(getMilesPerHour, never):Float;
	
	private static inline var MPS_TO_KPH = 3.6;
	private static inline var MPS_TO_MPH = 2.2369362920544022906227630637079455977093772369363;
	
	public static var zero:Speed = new Speed(0.0);
	
	public function new(metersPerSecond:Float) {
		this.metersPerSecond = metersPerSecond;
	}
	
	public function reset():Void {
		metersPerSecond = 0;
	}
	
	public inline function isZero() {
		return metersPerSecond == 0;
	}
	
	public inline function isFasterThanZero() {
		return !this.isZero();
	}
	
	public inline function isFasterThan(speed:Speed):Bool {
		return metersPerSecond > speed.metersPerSecond;
	}
	
	public inline function isSlowerThan(speed:Speed):Bool { 
		return metersPerSecond < speed.metersPerSecond;
	}
	
	public function equals(speed:Speed):Bool {
		return MathUtil.floatEquals(metersPerSecond, speed.metersPerSecond);
	}
	
	public function clone():Speed {
		return new Speed(metersPerSecond);
	}
	
	function getKmPerHour() {
		return metersPerSecond * MPS_TO_KPH;
	}
	
	function getMilesPerHour() {
		return metersPerSecond * MPS_TO_MPH;
	}
	
	public function toString() {
		return metersPerSecond + " mps";
	}
}